#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#define N_MAX 100

#define DFS_TREE	(1 << 4)
#define DFS_NOT_TREE	(1 << 5)
#define COLOR_WHITE	0
#define COLOR_GRAY	1
#define COLOR_BLACK	2

struct Node {
	int x;
	Node *next;
};

struct adjlist {
	Node *first;
	Node *last;
	int8_t size;

	/* Other attributes */
	int8_t color;
	int8_t visited;
	int    distance;
};


static void
pushback(struct adjlist *al, int x)
{
	Node *newnode;

	newnode = (Node *) malloc(sizeof (Node));
	newnode->x = x;
	newnode->next = NULL;
	if (!al->first)
		al->first = newnode;
	else
		al->last->next = newnode;
	al->last = newnode;
	al->size++;
}

static void
free_al(struct adjlist *al)
{
	struct Node *n, *p;
	p = n = al->first;
	while (n) {
		n = n->next;
		free(p);
		p = n;
	}
}

/*
static int
dfs_chk_connection(struct adjlist * const al, const int start)
{
	Node *node = NULL;

	al[start].visited = 1;
	node = al[start].first;

	while (node) {
		if (!al[node->x].visited)
			dfs_chk_connection(al, node->x);
		node = node->next;
	}

	return (0);
}
*/

static int
dfs_chk_cycles(struct adjlist * const al, const int start, const int sender,
		const int distance)
{
	int ret = 0;
	Node *nd = NULL;

	if (al[start].color == COLOR_GRAY)
		return (DFS_NOT_TREE);

	al[start].color   = COLOR_GRAY;
	nd                = al[start].first;
	al[start].visited = 1;

	while (nd) {
		if (nd->x == sender)
			goto cont;
		ret = dfs_chk_cycles(al, nd->x, start, distance + 1);
		if (ret == DFS_NOT_TREE)
			return (DFS_NOT_TREE);
		/* if (ret == DFS_TREE) goto cont; */
cont:
		nd = nd->next;
	}

	al[start].color = COLOR_BLACK;

	return (DFS_TREE);
}

int
main(void)
{
	static int	G[N_MAX][N_MAX];
	static struct adjlist AL[100];
	char		*read_ptr;
	int		n, j;
	register int	i = 0;
	int		ans = -1;

	(void) scanf("%d", &n);

	for (i = 0; i < n; ++i)
		for (j = 0; j < n; ++j) {
			(void) scanf("%d", &G[i][j]);
			if (G[i][j])
				pushback(&AL[i], j);
		}

	for (i = 0; i < n; i++) {
		AL[i].color = COLOR_WHITE;
		AL[i].visited = AL[i].distance = 0;
	}

	(void) fprintf(stderr, " starting from i=0\n");
	ans = dfs_chk_cycles(AL, 0, 0, 0);
	for (i = 0; i < n; i++)
		if (!AL[i].visited) {
			(void) fprintf(stderr, " not connected\n");
			(void) puts("NO");
			goto out;
		}

	if (ans == DFS_TREE)
		(void) puts("YES");
	else
		(void) puts("NO");
out:
	for (i = 0; i < n; i++)
		free_al(&AL[i]);
	return (0);
}
